package view;

import java.awt.Dialog;
import java.awt.GridLayout;

import javax.swing.JDialog;
import javax.swing.JFrame;

public class ChickenDialog extends JDialog implements Actionable {

	static final long serialVersionUID = 9996665;
	PokerView poker;
	
	InputButton[] dc;
	InputButton returner;
	
	int playerCount;
	
	public ChickenDialog(PokerView poker, int playerCount) {
		super(poker, "", Dialog.ModalityType.DOCUMENT_MODAL);
		setLayout(new GridLayout(playerCount+1, 1));
		
		dc = new InputButton[playerCount];
		for(int i=0; i<playerCount; i++) {
			dc[i] = new InputButton(this, "Odłącz gracza " + (i+1));
			add(dc[i]);
		}
		returner = new InputButton(this, "Wróć");
		add(returner);
		
		
		this.playerCount = playerCount;
		this.poker = poker;
		setBounds(200, 200, 200, 200);
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setUndecorated(true);
		setResizable(false);
		setVisible(false);
	}

	@Override
	public void action(InputButton b) {
		int i;
		for(i=0; i<playerCount; i++) {
			if(b == dc[i]) {
				poker.disconnect(i+1);
				break;
			}
		}
		setVisible(false);
		poker.requestFocus();
	}
	
	public void setPlayerCount(int playerCount) {
		removeAll();
		setLayout(new GridLayout(playerCount+1, 1));
		for(int i=0; i<playerCount; i++) {
			add(dc[i]);
		}
		add(returner);
		validate();
		revalidate();
		repaint();
		this.playerCount = playerCount;
	}

	@Override
	public void action(CardLabel cl) {
		// TODO Auto-generated method stub
		
	}
}
